package com.xci.platform.auth.entity;

import cn.afterturn.easypoi.excel.annotation.Excel;
import cn.afterturn.easypoi.excel.annotation.ExcelIgnore;
import com.xci.platform.core.Constant;
import lombok.Data;

import javax.validation.constraints.NotNull;
import java.io.Serializable;
import java.util.Date;

/**
 * 系统历史记录
 */
@Data
public class HistoryEntity implements Serializable {

    private static final long serialVersionUID = 1L;

    /**
     * 历史记录主键
     */
    @ExcelIgnore
    private String id;

    /**
     * 表名称
     */
    @Excel(name = "表名称", width = 30)
    private String tableName;

    /**
     * 表说明
     */
    @Excel(name = "表说明", width = 30)
    private String tableCaption;

    /**
     * 主键名
     */
    @Excel(name = "主键名")
    private String keyName;

    /**
     * 主键值
     */
    @Excel(name = "主键值", width = 40)
    private String keyValue;

    /**
     * 操作前数据
     */
    @Excel(name = "操作前数据", width = 40)
    private String beforeData;

    /**
     * 操作后数据
     */
    @Excel(name = "操作后数据", width = 40)
    private String afterData;

    /**
     * 操作消息
     */
    @Excel(name = "操作消息", width = 40)
    private String message;

    /**
     * 操作类型 1: 新增 2: 修改 3: 删除
     */
    @NotNull(message = "操作类型不能为空")
    @ExcelIgnore
    private Integer operateType;

    /**
     * 操作类型
     */
    @Excel(name = "操作类型")
    private String operateTypeText;

    /**
     * 操作用户主键
     */
    @ExcelIgnore
    private String operateUserId;

    /**
     * 操作用户
     */
    @Excel(name = "操作用户")
    private String operateUserName;

    /**
     * 操作日期
     */
    @Excel(name = "操作日期", width = 20, exportFormat = Constant.DefaultDateTimePattern)
    private Date operateDateTime;

    public String getOperateTypeText() {
        //操作类型 1: 新增 2: 修改 3: 删除
        switch (operateType) {
            case 1:
                return "新增";
            case 2:
                return "修改";
            case 3:
                return "删除";
        }
        return Constant.Empty;
    }
}
